package com.wuliupai.delivery.wuliupaidelivery.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wuliupai.delivery.wuliupaidelivery.R;
import com.wuliupai.delivery.wuliupaidelivery.db.CityHistoryBean;

import java.util.List;

/**
 * Descriptions：手动输入筛选地址列表的adapter
 * <p>
 * Author：ChenME
 * Date：2017/1/5
 * Email：ibelieve1210@163.com
 */
public class PlaceSearchAdapter extends BaseAdapter {

    private List<CityHistoryBean> dataList;
    private Context context;

    public PlaceSearchAdapter(Context context, List<CityHistoryBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return null != dataList ? dataList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_place_search_lv, null);
            holder.tv_searchResult = (TextView) convertView.findViewById(R.id.tv_searchResult);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        try {
            CityHistoryBean result = dataList.get(position);
            holder.tv_searchResult.setText(result.getArea() + " - " + result.getCity() + " - " + result.getProvince());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_searchResult;
    }
}
